<?php

namespace App\Models;

use Illuminate\Auth\Authenticatable;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Laravel\Lumen\Auth\Authorizable;

class Sys_District extends Model implements AuthenticatableContract, AuthorizableContract
{
    use Authenticatable, Authorizable, HasFactory;

    /**
     * 关联到模型的数据表
     *
     * @var string
     */
    protected $table = 'sys_district';

    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = [
        'pid',
        'district',
        'level'
    ];

    public static function getFilter($filter)
    {
        return self::where('parent_id',$filter['parent_id']);
    }

    public static function getDistrictName($code)
    {
        $result = self::where('code',$code)->first();
        return $result->name;
    }

    public static function getDistrictCode($name)
    {
        $result = self::where('name','Like','%'.$name.'%')->first();
        return $result->code;
    }
}
